/**
 * Sample Database
 * @author YUN
 */
package a.db;

import android.net.Uri;
import android.provider.BaseColumns;

public class MyDatabase {

	static final String AUTHORITY = "a.a.MyDatabase";
	static final Uri BASE_CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/");

	// PlayListsTable
	public static final class Test extends SqliteTable implements BaseColumns {
		static final String TABLE_NAME = "test";
		public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE_NAME);
		static final String TEST_TYPE = "vnd.android.cursor.dir/vnd.reco.test";
		static final String TEST_ITEM_TYPE = "vnd.android.cursor.item/vnd.reco.test";

		// columns
		/** type:Text */
		public static final String NAME = "name";

		public Test() {
			super(TABLE_NAME);
			addIntegerColumn(_ID, "PRIMARY KEY AUTOINCREMENT NOT NULL");
			addTextColumn(NAME, "NOT NULL");
		}
	}

	public static final class SectionTest extends SqliteView implements BaseColumns {
		static final String TABLE_NAME = "section_test";
		public static final Uri CONTENT_URI = Uri.withAppendedPath(BASE_CONTENT_URI, TABLE_NAME);
		static final String SECTION_TEST_TYPE = "vnd.android.cursor.dir/vnd.reco.section_test";
		static final String SECTION_TEST_ITEM_TYPE = "vnd.android.cursor.item/vnd.reco.section_test";

		/** type:Text */
		public static final String NAME = "name";

		public SectionTest() {
			super(TABLE_NAME);

			addSelect(_ID, "sub.%s", _ID);
			addSelect(NAME, "sub.%s", NAME);
			setFrom("(SELECT %s,%s FROM %s " +
					"UNION ALL " +
					"SELECT -1, SUBSTR(%s,1,1) section FROM %s GROUP BY section) sub",
					_ID,
					NAME,
					Test.TABLE_NAME,
					NAME,
					Test.TABLE_NAME);
			setOrderBy(NAME);
		}
	}
}
